#nullable enable

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using PHMEE.Controllers;
using Volo.Abp.Application.Dtos;

namespace PHMEE.EnergyEfficiency;

/// <summary>
/// Ams digital 开关量
/// </summary>
[Route("api/ams/digital-signal")]
public class DigitalSignalController : PHMEEController, IDigitalSignalAppService
{
    private readonly IDigitalSignalAppService _digitalSignalAppService;

    public DigitalSignalController(IDigitalSignalAppService digitalSignalAppService)
    {
        _digitalSignalAppService = digitalSignalAppService;
    }

    /// <summary>
    /// 获取实时开关量信号
    /// </summary>
    /// <param name="vesselId"></param>
    /// <returns></returns>
    [Route("GetRealtimeDigitalSignals")]
    [HttpGet]
    public Task<List<DigitalGroupDto>> GetRealtimeDigitalSignalsAsync(Guid vesselId)
    {
        return _digitalSignalAppService.GetRealtimeDigitalSignalsAsync(vesselId);
    }

    /// <summary>
    /// 查询报警记录
    /// </summary>
    /// <param name="vesselId"></param>
    /// <returns></returns>
    [Route("GetDigitalAlarmRecords")]
    [HttpGet]
    public Task<List<DigitalSignalDto>> GetDigitalAlarmRecordsAsync(Guid vesselId)
    {
        return _digitalSignalAppService.GetDigitalAlarmRecordsAsync(vesselId);
    }

    /// <summary>
    /// 查询每个 tag 最新状态为 Alarm 的记录
    /// </summary>
    /// <param name="vesselId"></param>
    /// <returns></returns>
    [Route("GetEveryTagsLatestAlarmRecords")]
    [HttpGet]
    public Task<List<DigitalSignalDto>> GetEveryTagsLatestAlarmRecordsAsync(Guid vesselId)
    {
        return _digitalSignalAppService.GetEveryTagsLatestAlarmRecordsAsync(vesselId);
    }

    /// <summary>
    /// 根据 AMS Group，查询实时的报警记录
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="amsGroup"></param>
    /// <returns></returns>
    [Route("GetRealtimeDigitalAlarmRecordsByAmsGroup")]
    [HttpGet]
    [Obsolete]
    public Task<List<DigitalSignalDto>> GetRealtimeDigitalAlarmRecordsByAmsGroupAsync(Guid vesselId, [Required] string amsGroup)
    {
        return _digitalSignalAppService.GetRealtimeDigitalAlarmRecordsByAmsGroupAsync(vesselId, amsGroup);
    }

    /// <summary>
    /// 查询报警历史
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="tagName"></param>
    /// <param name="tagDescription"></param>
    /// <param name="startDateTime"></param>
    /// <param name="endDateTime"></param>
    /// <param name="skipCount"></param>
    /// <param name="maxResultCount"></param>
    /// <returns></returns>
    [Route("GetDigitalAlarmHistory")]
    [HttpGet]
    public Task<PagedResultDto<DigitalSignalDto>> GetDigitalAlarmHistoryAsync(Guid vesselId, string? tagName,
        string? tagDescription, [Required] DateTime startDateTime, [Required] DateTime endDateTime,
        [Required][Range(0, int.MaxValue)] int skipCount,
        [Required][Range(0, int.MaxValue)] int maxResultCount)
    {
        return _digitalSignalAppService.GetDigitalAlarmHistoryAsync(vesselId, tagName, tagDescription, startDateTime,
            endDateTime, skipCount, maxResultCount);
    }
}